package su.validator.service;

import java.util.List;
import javax.annotation.Resource;

import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;

import cn.hutool.json.JSONUtil;
import lombok.extern.slf4j.Slf4j;
import su.validator.core.ErrorsCollector;
import su.validator.core.ValidateErrors;
import su.validator.core.ValidateService;
import su.validator.core.pwd.Password;
import su.validator.param.SingleForm;
import su.validator.param.UserValidateForm;


@Service
@Slf4j
public class TestServiceImpl implements TestService {

    @Resource
    @Lazy
    private ValidateService validateService;

    @Override
    public void singleValidate(Long id) {
        log.info(">> singleValidate ");
    }

    @Override
    public void singleValidate(SingleForm singleForm) {
        ErrorsCollector errorsCollector = new ErrorsCollector();
        validateService.validateBusiness(singleForm, errorsCollector);
        List<ValidateErrors.Error> errors = errorsCollector.getValidateErrors().getErrors();
        System.out.println(errorsCollector.getValidateErrors().hasError());
        System.out.println(JSONUtil.toJsonStr(errors));
    }

    @Override
    public void customSingleValidate(Password password) {
        log.info(">> customSingleValidate");
    }

    @Override
    public void validateForm(UserValidateForm userValidateForm) {

    }
}
